<?php


abstract class BaseKillmail extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $content;


	
	protected $victim_id;


	
	protected $victim;


	
	protected $alliance;


	
	protected $corporation;


	
	protected $destroyed;


	
	protected $system;


	
	protected $security;


	
	protected $damage_taken;


	
	protected $kill_date;

	
	protected $asfGuardUser;

	
	protected $collChallenges;

	
	protected $lastChallengeCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getContent()
	{

		return $this->content;
	}

	
	public function getVictimId()
	{

		return $this->victim_id;
	}

	
	public function getVictim()
	{

		return $this->victim;
	}

	
	public function getAlliance()
	{

		return $this->alliance;
	}

	
	public function getCorporation()
	{

		return $this->corporation;
	}

	
	public function getDestroyed()
	{

		return $this->destroyed;
	}

	
	public function getSystem()
	{

		return $this->system;
	}

	
	public function getSecurity()
	{

		return $this->security;
	}

	
	public function getDamageTaken()
	{

		return $this->damage_taken;
	}

	
	public function getKillDate($format = 'Y-m-d H:i:s')
	{

		if ($this->kill_date === null || $this->kill_date === '') {
			return null;
		} elseif (!is_int($this->kill_date)) {
						$ts = strtotime($this->kill_date);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [kill_date] as date/time value: " . var_export($this->kill_date, true));
			}
		} else {
			$ts = $this->kill_date;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = KillmailPeer::ID;
		}

	} 
	
	public function setContent($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->content !== $v) {
			$this->content = $v;
			$this->modifiedColumns[] = KillmailPeer::CONTENT;
		}

	} 
	
	public function setVictimId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->victim_id !== $v) {
			$this->victim_id = $v;
			$this->modifiedColumns[] = KillmailPeer::VICTIM_ID;
		}

		if ($this->asfGuardUser !== null && $this->asfGuardUser->getId() !== $v) {
			$this->asfGuardUser = null;
		}

	} 
	
	public function setVictim($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->victim !== $v) {
			$this->victim = $v;
			$this->modifiedColumns[] = KillmailPeer::VICTIM;
		}

	} 
	
	public function setAlliance($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->alliance !== $v) {
			$this->alliance = $v;
			$this->modifiedColumns[] = KillmailPeer::ALLIANCE;
		}

	} 
	
	public function setCorporation($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->corporation !== $v) {
			$this->corporation = $v;
			$this->modifiedColumns[] = KillmailPeer::CORPORATION;
		}

	} 
	
	public function setDestroyed($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->destroyed !== $v) {
			$this->destroyed = $v;
			$this->modifiedColumns[] = KillmailPeer::DESTROYED;
		}

	} 
	
	public function setSystem($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->system !== $v) {
			$this->system = $v;
			$this->modifiedColumns[] = KillmailPeer::SYSTEM;
		}

	} 
	
	public function setSecurity($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->security !== $v) {
			$this->security = $v;
			$this->modifiedColumns[] = KillmailPeer::SECURITY;
		}

	} 
	
	public function setDamageTaken($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->damage_taken !== $v) {
			$this->damage_taken = $v;
			$this->modifiedColumns[] = KillmailPeer::DAMAGE_TAKEN;
		}

	} 
	
	public function setKillDate($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [kill_date] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->kill_date !== $ts) {
			$this->kill_date = $ts;
			$this->modifiedColumns[] = KillmailPeer::KILL_DATE;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->content = $rs->getString($startcol + 1);

			$this->victim_id = $rs->getInt($startcol + 2);

			$this->victim = $rs->getString($startcol + 3);

			$this->alliance = $rs->getString($startcol + 4);

			$this->corporation = $rs->getString($startcol + 5);

			$this->destroyed = $rs->getString($startcol + 6);

			$this->system = $rs->getString($startcol + 7);

			$this->security = $rs->getString($startcol + 8);

			$this->damage_taken = $rs->getInt($startcol + 9);

			$this->kill_date = $rs->getTimestamp($startcol + 10, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Killmail object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(KillmailPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			KillmailPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(KillmailPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->asfGuardUser !== null) {
				if ($this->asfGuardUser->isModified()) {
					$affectedRows += $this->asfGuardUser->save($con);
				}
				$this->setsfGuardUser($this->asfGuardUser);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = KillmailPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += KillmailPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collChallenges !== null) {
				foreach($this->collChallenges as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->asfGuardUser !== null) {
				if (!$this->asfGuardUser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
				}
			}


			if (($retval = KillmailPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collChallenges !== null) {
					foreach($this->collChallenges as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = KillmailPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getContent();
				break;
			case 2:
				return $this->getVictimId();
				break;
			case 3:
				return $this->getVictim();
				break;
			case 4:
				return $this->getAlliance();
				break;
			case 5:
				return $this->getCorporation();
				break;
			case 6:
				return $this->getDestroyed();
				break;
			case 7:
				return $this->getSystem();
				break;
			case 8:
				return $this->getSecurity();
				break;
			case 9:
				return $this->getDamageTaken();
				break;
			case 10:
				return $this->getKillDate();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = KillmailPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getContent(),
			$keys[2] => $this->getVictimId(),
			$keys[3] => $this->getVictim(),
			$keys[4] => $this->getAlliance(),
			$keys[5] => $this->getCorporation(),
			$keys[6] => $this->getDestroyed(),
			$keys[7] => $this->getSystem(),
			$keys[8] => $this->getSecurity(),
			$keys[9] => $this->getDamageTaken(),
			$keys[10] => $this->getKillDate(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = KillmailPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setContent($value);
				break;
			case 2:
				$this->setVictimId($value);
				break;
			case 3:
				$this->setVictim($value);
				break;
			case 4:
				$this->setAlliance($value);
				break;
			case 5:
				$this->setCorporation($value);
				break;
			case 6:
				$this->setDestroyed($value);
				break;
			case 7:
				$this->setSystem($value);
				break;
			case 8:
				$this->setSecurity($value);
				break;
			case 9:
				$this->setDamageTaken($value);
				break;
			case 10:
				$this->setKillDate($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = KillmailPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setContent($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setVictimId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setVictim($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setAlliance($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCorporation($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDestroyed($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setSystem($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setSecurity($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setDamageTaken($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setKillDate($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(KillmailPeer::DATABASE_NAME);

		if ($this->isColumnModified(KillmailPeer::ID)) $criteria->add(KillmailPeer::ID, $this->id);
		if ($this->isColumnModified(KillmailPeer::CONTENT)) $criteria->add(KillmailPeer::CONTENT, $this->content);
		if ($this->isColumnModified(KillmailPeer::VICTIM_ID)) $criteria->add(KillmailPeer::VICTIM_ID, $this->victim_id);
		if ($this->isColumnModified(KillmailPeer::VICTIM)) $criteria->add(KillmailPeer::VICTIM, $this->victim);
		if ($this->isColumnModified(KillmailPeer::ALLIANCE)) $criteria->add(KillmailPeer::ALLIANCE, $this->alliance);
		if ($this->isColumnModified(KillmailPeer::CORPORATION)) $criteria->add(KillmailPeer::CORPORATION, $this->corporation);
		if ($this->isColumnModified(KillmailPeer::DESTROYED)) $criteria->add(KillmailPeer::DESTROYED, $this->destroyed);
		if ($this->isColumnModified(KillmailPeer::SYSTEM)) $criteria->add(KillmailPeer::SYSTEM, $this->system);
		if ($this->isColumnModified(KillmailPeer::SECURITY)) $criteria->add(KillmailPeer::SECURITY, $this->security);
		if ($this->isColumnModified(KillmailPeer::DAMAGE_TAKEN)) $criteria->add(KillmailPeer::DAMAGE_TAKEN, $this->damage_taken);
		if ($this->isColumnModified(KillmailPeer::KILL_DATE)) $criteria->add(KillmailPeer::KILL_DATE, $this->kill_date);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(KillmailPeer::DATABASE_NAME);

		$criteria->add(KillmailPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setContent($this->content);

		$copyObj->setVictimId($this->victim_id);

		$copyObj->setVictim($this->victim);

		$copyObj->setAlliance($this->alliance);

		$copyObj->setCorporation($this->corporation);

		$copyObj->setDestroyed($this->destroyed);

		$copyObj->setSystem($this->system);

		$copyObj->setSecurity($this->security);

		$copyObj->setDamageTaken($this->damage_taken);

		$copyObj->setKillDate($this->kill_date);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getChallenges() as $relObj) {
				$copyObj->addChallenge($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new KillmailPeer();
		}
		return self::$peer;
	}

	
	public function setsfGuardUser($v)
	{


		if ($v === null) {
			$this->setVictimId(NULL);
		} else {
			$this->setVictimId($v->getId());
		}


		$this->asfGuardUser = $v;
	}


	
	public function getsfGuardUser($con = null)
	{
		if ($this->asfGuardUser === null && ($this->victim_id !== null)) {
						include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardUserPeer.php';

			$this->asfGuardUser = sfGuardUserPeer::retrieveByPK($this->victim_id, $con);

			
		}
		return $this->asfGuardUser;
	}

	
	public function initChallenges()
	{
		if ($this->collChallenges === null) {
			$this->collChallenges = array();
		}
	}

	
	public function getChallenges($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseChallengePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collChallenges === null) {
			if ($this->isNew()) {
			   $this->collChallenges = array();
			} else {

				$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

				ChallengePeer::addSelectColumns($criteria);
				$this->collChallenges = ChallengePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

				ChallengePeer::addSelectColumns($criteria);
				if (!isset($this->lastChallengeCriteria) || !$this->lastChallengeCriteria->equals($criteria)) {
					$this->collChallenges = ChallengePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastChallengeCriteria = $criteria;
		return $this->collChallenges;
	}

	
	public function countChallenges($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseChallengePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

		return ChallengePeer::doCount($criteria, $distinct, $con);
	}

	
	public function addChallenge(Challenge $l)
	{
		$this->collChallenges[] = $l;
		$l->setKillmail($this);
	}


	
	public function getChallengesJoinsfGuardUserRelatedByP1Id($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseChallengePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collChallenges === null) {
			if ($this->isNew()) {
				$this->collChallenges = array();
			} else {

				$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

				$this->collChallenges = ChallengePeer::doSelectJoinsfGuardUserRelatedByP1Id($criteria, $con);
			}
		} else {
									
			$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

			if (!isset($this->lastChallengeCriteria) || !$this->lastChallengeCriteria->equals($criteria)) {
				$this->collChallenges = ChallengePeer::doSelectJoinsfGuardUserRelatedByP1Id($criteria, $con);
			}
		}
		$this->lastChallengeCriteria = $criteria;

		return $this->collChallenges;
	}


	
	public function getChallengesJoinsfGuardUserRelatedByP2Id($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseChallengePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collChallenges === null) {
			if ($this->isNew()) {
				$this->collChallenges = array();
			} else {

				$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

				$this->collChallenges = ChallengePeer::doSelectJoinsfGuardUserRelatedByP2Id($criteria, $con);
			}
		} else {
									
			$criteria->add(ChallengePeer::KILLMAIL_ID, $this->getId());

			if (!isset($this->lastChallengeCriteria) || !$this->lastChallengeCriteria->equals($criteria)) {
				$this->collChallenges = ChallengePeer::doSelectJoinsfGuardUserRelatedByP2Id($criteria, $con);
			}
		}
		$this->lastChallengeCriteria = $criteria;

		return $this->collChallenges;
	}

} 